<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta charset="utf-8">
		<title>Sam君家的功夫猫</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="full-screen" content="yes">
		<meta name="screen-orientation" content="portrait">
		<meta name="x5-fullscreen" content="true">
		<style>
			canvas {
				image-rendering: optimizeSpeed;
				image-rendering: -moz-crisp-edges;
				image-rendering: -webkit-optimize-contrast;
				image-rendering: -o-crisp-edges;
				image-rendering: optimize-contrast;
				-ms-interpolation-mode: nearest-neighbor;
			}
			body{ margin:0; height:100%}
			html{ height:100%}
	        .fullscreen {
	            position            :absolute;
	            left                :0;
	            top                 :0;
	            width               :100%;
	            height              :100%;
	            -moz-opacity        :0.5;
	            z-index             :100;
	        }
		</style>
		<script src="js/mui.min.js"></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		<script type="text/javascript" charset="utf-8">
			mui.init();
		</script>
		<script type="text/javascript" src="./js/common.js"></script>
		<script type="text/javascript">
			var shares=null;
			var Intent=null,File=null,Uri=null,main=null;
			// H5 plus事件处理
			function plusReady(){
				updateSerivces();
				if(plus.os.name=="Android"){
					main = plus.android.runtimeMainActivity();
					Intent = plus.android.importClass("android.content.Intent");
					File = plus.android.importClass("java.io.File");
					Uri = plus.android.importClass("android.net.Uri");
				}
			}
			if(window.plus){
				plusReady();
			}else{
				document.addEventListener("plusready",plusReady,false);
			}
			/**
			 * 更新分享服务
			 */
			function updateSerivces(){
				plus.share.getServices( function(s){
					shares={};
					for(var i in s){
						var t=s[i];
						shares[t.id]=t;
					}
				}, function(e){
					outSet( "获取分享服务列表失败："+e.message );
				} );
			}
			function share4Android(shareTip,shareText){
					    var Context = plus.android.importClass("android.content.Intent");
					    var Main = plus.android.runtimeMainActivity();
					    var shareIntent=new Context(Context.ACTION_SEND);
					    var p = "";
						if(pic&&pic.realUrl){
							p = pic.realUrl;
							if(p.substr(0,7)==="file://"){
								p=p.substr(7);
							}else if(p.sub(0)!=="/"){
								p=plus.io.convertLocalFileSystemURL(p);
							}
						}
						var f = new File(p);
						var uri = Uri.fromFile(f);
						if(f.exists()&&f.isFile()){
							console.log("image/*");
							shareIntent.setType("image/*");
							shareIntent.putExtra(Context.EXTRA_STREAM,uri);
						}else{
							console.log("text/plain");
							shareIntent.setType("text/plain");
						}
						shareIntent.putExtra(Context.EXTRA_SUBJECT,shareTip);
						shareIntent.putExtra(Context.EXTRA_TEXT,shareText);
						shareIntent.setFlags(Context.FLAG_ACTIVITY_NEW_TASK);
					    Main.startActivity(Context.createChooser(shareIntent,"系统分享"));
					}
			
			/**
			 * 调用系统分享
			 * 调用
			 */
			function shareSystem() {
				if(plus.os.name!=="Android"){
					share4Android("功夫猫",sharecontent.value)
				}else{
					var intent=new Intent(Intent.ACTION_SEND);
					var p = "";
					if(pic&&pic.realUrl){
						p = pic.realUrl;
						if(p.substr(0,7)==="file://"){
							p=p.substr(7);
						}else if(p.sub(0)!=="/"){
							p=plus.io.convertLocalFileSystemURL(p);
						}
					}
					var f = new File(p);
					var uri = Uri.fromFile(f);
					if(f.exists()&&f.isFile()){
						console.log("image/*");
						intent.setType("image/*");
						intent.putExtra(Intent.EXTRA_STREAM,uri);
					}else{
						console.log("text/plain");
						intent.setType("text/plain");
					}
					intent.putExtra(Intent.EXTRA_SUBJECT,"功夫猫");
					intent.putExtra(Intent.EXTRA_TEXT,sharecontent.value);
					intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					main.startActivity(Intent.createChooser(intent,"系统分享"));
				}
			}
			/**
			   * 分享操作
			   * @param {JSON} sb 分享操作对象s.s为分享通道对象(plus.share.ShareService)
			   * @param {Boolean} bh 是否分享链接
			   */
			function shareAction(sb,bh) {
				outSet( "分享操作：" );
				if(!sb||!sb.s){
					console.log("无效的分享服务！");
					outLine( "无效的分享服务！" );
					return;
				}
				var msg={content:sharecontent.value,extra:{scene:sb.x}};
				if(bh){
					console.log(sharehref.value)
					msg.href=sharehref.value;
					if(sharehrefTitle&&sharehrefTitle.value!=""){
						msg.title=sharehrefTitle.value;
					}
					if(sharehrefDes&&sharehrefDes.value!=""){
						msg.content=sharehrefDes.value;
					}
					msg.thumbs=["_www/gfm.png"];
					msg.pictures=["_www/gfm.png"];
				}else{
					if(pic&&pic.realUrl){
						msg.pictures=[pic.realUrl];
					}
				}
				// 发送分享
				if ( sb.s.authenticated ) {
					outLine( "---已授权---" );
					shareMessage(msg,sb.s);
				} else {
					outLine( "---未授权---" );
					sb.s.authorize( function(){
							shareMessage(msg,sb.s);
						},function(e){
						outLine( "认证授权失败："+e.code+" - "+e.message );
					});
				}
			}
			/**
			   * 发送分享消息
			   * @param {JSON} msg
			   * @param {plus.share.ShareService} s
			   */
			function shareMessage(msg,s){
				outLine(JSON.stringify(msg));
				s.send( msg, function(){
					outLine( "分享到\""+s.description+"\"成功！ " );
					mui.toast("分享到\""+s.description+"\"成功！ ");
				}, function(e){
					outLine( "分享到\""+s.description+"\"失败: "+JSON.stringify(e) );
					mui.toast("分享到\""+s.description+"\"失败: "+JSON.stringify(e));
				} );
			}
			/**
			 * 解除所有分享服务的授权
			 */
			function cancelAuth(){try{
				outSet( "解除授权：" );
				for ( var i in shares ) {
					var s = shares[i];
					if ( s.authenticated ) {
						outLine( "取消\""+s.description+"\"");
					}
					s.forbid();
				}
				// 取消授权后需要更新服务列表
				updateSerivces();
				outLine( "操作成功！" );}catch(e){alert(e);}
			}
			// 拍照添加图片分享
			function shareCameraPicture(){
				outSet("拍照添加分享图片：");
				var cmr=plus.camera.getCamera();
				cmr.captureImage(function(p){
					plus.io.resolveLocalFileSystemURL(p,function(entry){
						pic.src=entry.toLocalURL();
						pic.realUrl=p;
						outLine("拍照图片："+pic.realUrl);
					},function(e){
						outLine("读取拍照文件错误："+e.message);
					} );
				},function(e){
					outLine( "拍照失败："+e.message );
				});
			}
			// 从相册添加图片分享
			function shareGalleryPicture(){
				outSet("从相册添加分享图片：");
				plus.gallery.pick(function(p){
					// 从相册返回的路径不需要转换可以直接使用
					pic.src=p;
					pic.realUrl=pic.src;
					outLine("选择图片："+pic.realUrl);
			//      plus.io.resolveLocalFileSystemURL(p,function(entry){
			//			pic.src=entry.toLocalURL();
			//			pic.realUrl=pic.src;
			//			outLine("选择图片："+pic.realUrl);
			//		},function(e){
			//			outLine("读取拍照文件错误："+e.message);
			//		} );
			    });
			}
			// 使用Logo图片分享
			function shareLogoPicture(){
				outSet("使用Logo分享图片：");
				var url="_www/logo.png";
				plus.io.resolveLocalFileSystemURL(url,function(entry){
					pic.src=entry.toLocalURL();
					pic.realUrl=url;
				},function(e){
					outLine("读取Logo文件错误："+e.message);
				} );
			}
			// 打开分享
			function shareShow(){
				var shareBts=[];
				// 更新分享列表
				var ss=shares['weixin'];
				if(navigator.userAgent.indexOf('StreamApp')<0&&navigator.userAgent.indexOf('qihoo')<0){  //在360流应用中微信不支持分享图片
					ss&&ss.nativeClient&&(shareBts.push({title:'微信朋友圈',s:ss,x:'WXSceneTimeline'}),
					shareBts.push({title:'微信好友',s:ss,x:'WXSceneSession'}));
				}
				ss=shares['sinaweibo'];
				ss&&shareBts.push({title:'新浪微博',s:ss});
				ss=shares['qq'];
				ss&&ss.nativeClient&&shareBts.push({title:'QQ',s:ss});
				// 弹出分享列表
				shareBts.length>0?plus.nativeUI.actionSheet({title:'分享',cancel:'取消',buttons:shareBts},function(e){
					(e.index>0)&&shareAction(shareBts[e.index-1],true);
				}):plus.nativeUI.alert('当前环境无法支持分享操作!');
			}
			// 分析链接
			function shareHref(){
				var shareBts=[];
				// 更新分享列表
				var ss=shares['weixin'];
				ss&&ss.nativeClient&&(shareBts.push({title:'微信朋友圈',s:ss,x:'WXSceneTimeline'}),
				shareBts.push({title:'微信好友',s:ss,x:'WXSceneSession'}));
				ss=shares['qq'];
				ss&&ss.nativeClient&&shareBts.push({title:'QQ',s:ss});
				// 弹出分享列表
				shareBts.length>0?plus.nativeUI.actionSheet({title:'分享链接',cancel:'取消',buttons:shareBts},function(e){
					(e.index>0)&&shareAction(shareBts[e.index-1],true);
				}):plus.nativeUI.alert('当前环境无法支持分享链接操作!');
			}
			
			

			// 播放文件相关对象
			var p=null,pt=null,pp=null,ps=null,pi=null;
			// 开始播放
			function startPlay( url ) {
				//ep.style.display = "none";
				//var L = pp.clientWidth;
				p = plus.audio.createPlayer( url );
				p.play( function () {
					outLine( "播放完成！" );
					// 播放完成
					//pt.innerText = timeToStr(d)+"/"+timeToStr(d);
					//ps.style.webkitTransition = "all 0.3s linear";
					//ps.style.width = L+"px";
					stopPlay();
				}, function ( e ) {
					outLine( "播放音频文件\""+url+"\"失败："+e.message );
				} );
				// 获取总时长
//				var d = p.getDuration();
//				if ( !d ) {
//					pt.innerText = "00:00:00/"+timeToStr(d);
//				}
//				pi = setInterval( function () {
//					if ( !d ) { // 兼容无法及时获取总时长的情况
//						d = p.getDuration();
//					}
//					var c = p.getPosition();
//					if ( !c ) {  // 兼容无法及时获取当前播放位置的情况
//						return;
//					}
//					pt.innerText = timeToStr(c)+"/"+timeToStr(d);
//					var pct = Math.round(L*c/d);
//					if ( pct < 8 ) {
//						pct = 8;
//					}
//					ps.style.width = pct+"px";
//				}, 1000 );
			}
			// 停止播放
			function stopPlay() {
				clearInterval(pi);
				pi=null;
				setTimeout(resetPlay,500);
				// 操作播放对象
				if(p){
					p.stop();
					p=null;
				}
			}
			// 重置播放页面内容
			function resetPlay() {
				//ep.style.display = "none";
				//ps.style.width = "8px";
				//ps.style.webkitTransition = "all 1s linear";
				//pt.innerText = "00:00:00/00:00:00";	
			}
		</script>
		<link rel="stylesheet" href="./css/common.css" type="text/css" charset="utf-8"/>
		<style type="text/css">
			#sharecontent{
				width:80%;
				-webkit-user-select:text;
				border: 1px solid #6C6C6C;
				-webkit-border-radius: 2px;
				border-radius: 2px;
			}
			#pic{
				width:100px;
				height:100px;
				/*border: 1px dashed #CCCCCC;*/
			}
			.sharehref{
				width:80%;
				-webkit-user-select:text;
				border: 1px solid #6C6C6C;
				-webkit-border-radius: 2px;
				border-radius: 2px;
				margin-bottom: .5em;
			}
		</style>
	</head>

	<body>

		<img width="500" height="500" style="position:absolute;top:-10000px;" src="index_files/icon.png">
		<div style="position:absolute;left:0xp;top:0px;z-index:10000;">
		</div>

		<div class="mui-content">

			<div id="Cocos2dGameContainer" class="fullscreen">
				<canvas id="gameCanvas" width="100%" height="100%" class="gameCanvas" tabindex="99" style="background-color: black; outline: none; width: 100%; height: 100%;">
				</canvas>

			</div>
			<script>
				window.wxData = {
					"desc": "神经病院又逃出了一只猫...小伙伴们真要跟喵星人较劲么？",
					"title": "喵星人简直要占领朋友圈的节奏，刚捉回去一只，又逃出来一只，唉！"
				};
				window.wxFriend = {
					"desc": '神经病院又逃出了一只猫...小伙伴们真要跟喵星人较劲么？',
					"title": "喵星人简直要占领朋友圈的节奏，刚捉回去一只，又逃出来一只，唉！"
				};

			</script>
			<script type="text/javascript" src="./js/cocos2d-html5.js"></script>
			<div style="font-family: 黑体; position: absolute; left: -100px; top: -100px; line-height: normal; font-size: 20px;"></div>
			<script type="text/javascript" src="./js/catnorris.js"></script>
			<div style="display:none">
				<img src="">
			</div>
			<input id="sharehref" class="sharehref" type="hidden" value="http://0312birdzhang.oschina.io/kongfucat/"/>
			<input id="sharehrefTitle" class="sharehref" type="hidden" value="我正在玩功夫猫，快来跟我PK吧" />
			<input id="sharehrefDes" class="sharehref" type="hidden" value="神经病院又逃出了一只猫...小伙伴们真要跟喵星人较劲么？" />
			<div style="display: none;">
				<img id="pic" src="gfm.png"/>
				<input id="sharecontent" type="hidden" value="我在玩Sam君家里的功夫猫，你也来试试吧"  />
				<div id="output">
				</div>
			</div>
		</div>
		
	</body>
	<script type="text/javascript" src="./js/immersed.js" ></script>
</html>